﻿using System.Collections.Generic;
using System.Data.Entity;
using Tango.Domain;

namespace Tango.Infrastructure.EntityFramework
{
    public class Database : DbContext, IDatabase, IUnitOfWork
    {
        public DbSet<Entry> Entries
        {
            get;
            set;
        }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            base.OnModelCreating(modelBuilder);
        }

        public void Commit()
        {
            SaveChanges();
        }

        public void InsertOnSubmit<T>(T entity)
            where T : class
        {
            Set<T>().Add(entity);
        }
        public void InsertAllOnSubmit<T>(IEnumerable<T> entities)
            where T : class
        {
            entities.ForEach(entity =>
            {
                Set<T>().Add(entity);
            });
        }
        public void DeleteOnSubmit<T>(T entity)
            where T : class
        {
            Set<T>().Remove(entity);
        }
        public void DeleteOnSubmit<T>(IEnumerable<T> entities)
            where T : class
        {
            entities.ForEach(entity =>
            {
                Set<T>().Remove(entity);
            });
        }
    }
}
